package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.WechatContactsFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by jjx on 2018/3/19.
 */
@Api(value = "微信截图好友数接口", description = "微信截图好友数接口")
@Controller
@RequestMapping("/weChatContacts")
public class WechatContactsController {

    @Resource
    private WechatContactsFacade wechatContactsFacade;

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改/保存",
            notes = "修改/保存",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        obj.put("id", wechatContactsFacade.save(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "逻辑删除",
            notes = "逻辑删除",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void delById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        boolean row = wechatContactsFacade.delById(jsonData);
        obj.put("result", String.valueOf(row));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @RequestMapping(value = "/getByUserId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过userId获取",
            notes = "通过userId获取",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getByUserId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        JSONObject resultList = wechatContactsFacade.getByUserId(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(resultList));
    }

    @RequestMapping(value = "/getByUserName.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过userName获取",
            notes = "通过userName获取",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getByUserName(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        JSONObject resultList = wechatContactsFacade.getByUserName(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(resultList));
    }
}
